<template>
    <div>
        <el-table
                :data="tableData"
                ref="multipleTable"
                border
                :stripe="true"
                style="width: 100%"
                @selection-change="handleSelectionChange">
            >
            <el-table-column
                    type="selection"
                    width="55">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="讲师姓名"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="intro"
                    label="讲师简介"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="career"
                    label="讲师资历"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="level"
                    label="头衔"
                    width="130">
                <template slot-scope="scope">
                    <span v-if="scope.row.level == 1"> 高级讲师 </span>
                    <span v-if="scope.row.level == 2"> 首席讲师 </span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="avatar"
                    label="讲师头像"
                    width="120">
                <template slot-scope="scope"><img :src="scope.row.avatar" style="height: 50px"></template>
            </el-table-column>
            <el-table-column
                    label="操作"
                    width="100">
                <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                    <el-button type="text" size="small">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                background
                layout="prev, pager, next"
                :page-size="pageSize"
                :total="total"
                @current-change="selectPage"
                >
        </el-pagination>
    </div>
</template>

<script>
    import {getTeachers} from '@/api/index'
    export default {
        name: "PageTwo",
        created(){

            let params = {
                pageIndex: this.pageIndex,
                pageSize: this.pageSize
            }
            getTeachers(params).then(res => {
                console.log('res', res)
                if (res.code == 0) {
                    this.tableData = res.data.rows
                    this.total = res.data.total
                    this.$notify({
                        title: '成功',
                        message: res.msg,
                        type: 'success'
                    });
                }
            })

        },
        methods: {
            handleClick(row) {
                console.log(row);
            },
            handleSelectionChange(val){
                this.multipleSelection = val;
            },
            selectPage(currentPage){
                this.pageIndex = currentPage
                let params = {
                    pageIndex: this.pageIndex,
                    pageSize: this.pageSize
                }
                getTeachers(params).then(res => {
                    console.log('res', res)
                    if (res.code == 0) {
                        this.tableData = res.data.rows
                        this.total = res.data.total
                    }
                })
            }
        },
        data() {
            return {
                total: null,
                pageIndex: 1,
                pageSize: 2,
                multipleSelection: [],
                tableData: []
            }
        }
    }
</script>

<style scoped>

</style>